#define ASYNC_QUERY_BODY(sql) if (!sql || !result_queue_) return false;

#define ASYNC_PQUERY_BODY(format, szQuery)                                                          \
    if(!format) { return false; }                                                                   \
    char szQuery[Database::MAX_QUERY_LENGTH];                                                       \
    ::std::va_list ap;                                                                              \
    va_start(ap, format);                                                                           \
    int res = ::node::util::string::vsnprintf( szQuery, Database::MAX_QUERY_LENGTH, format, ap );   \
    va_end(ap);                                                                                     \
    if(res == -1)                                                                                   \
    {                                                                                               \
        NODE_MAINLOGGER.error("SQL Query truncated (and not execute) for format: %s",format);       \
        return false;                                                                               \
    }                                                                                               \


namespace node {
    namespace db {

        template<class Class, typename ParamType1>
        bool Database::asyncQuery(Class* object, void (Class::*method)(::node::db::ResultSet*, ParamType1), ParamType1 param1, const char* sql)
        {
            ASYNC_QUERY_BODY(sql);
            return delay_thread_->delay(new SqlQuery(sql, new ::node::db::QueryCallback<Class, ParamType1>(object, method, (::node::db::ResultSet*)NULL, param1), result_queue_));
        }

        template<class Class, typename ParamType1>
        bool Database::asyncPQuery(Class* object, void (Class::*method)(::node::db::ResultSet*, ParamType1), ParamType1 param1, const char* format, ...)
        {
            ASYNC_PQUERY_BODY(format, szQuery)
            return asyncQuery(object, method, param1, szQuery);
        }

    }
}